package com.base.myproject.client.ui;

import com.extjs.gxt.ui.client.widget.Info;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Frame;
/**
 * 网页上面的查询窗口，目前是通过google查询
 * @author zgw
 *2009-7-7 上午11:27:13
 * javazgw@gmail.com
 */
public class BaseSerchHtml   {
	String searchstr = null;
	 Frame f = new Frame();
	 int type;//1 taoba.2 baidu 否则google
	public BaseSerchHtml()
	{
		
	}
	public BaseSerchHtml(int type)
	{
		this.type = type;
		
	}
	public Frame getSearchFrame()
	{
		f.setWidth("100%");
	
		/*if(f.getParent()!=null)
		{
			f.setHeight(DOM.getElementProperty(f.getParent().getElement(), "height"));
		}
		else
		{*/
		f.setHeight("445px");
//		}
	return f;
	}
	
	public Frame SearchHtml(String searchstr)
	{
		this.searchstr = searchstr;
		if(type==1)
		{
			 com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
				greetingService.UrlEncode(searchstr, "utf-8", "GBK", new AsyncCallback<String>(){

					@Override
					public void onFailure(Throwable caught) {
						Info.display("错误","网络中断");
						
					}

					@Override
					public void onSuccess(String result) {
						f.setUrl("http://s.taobao.com/search?q="+result);
						
					}
					
				});

			
			
		}
		else if(type == 2)
		{
			com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
			.create(com.base.myproject.client.tools.GreetingService.class);
			greetingService.UrlEncode(searchstr, "utf-8", "GBK", new AsyncCallback<String>(){

				@Override
				public void onFailure(Throwable caught) {
					Info.display("错误","网络中断");
					
				}

				@Override
				public void onSuccess(String result) {
					f.setUrl("http://www.baidu.com/s?wd="+result);
					
				}
				
			});

			
		}
		else if(type == 3)
		{
			

			com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
			.create(com.base.myproject.client.tools.GreetingService.class);
			greetingService.UrlEncode(searchstr, "utf-8", "GBK", new AsyncCallback<String>(){

				@Override
				public void onFailure(Throwable caught) {
					Info.display("错误","网络中断");
					
				}

				@Override
				public void onSuccess(String result) {
					f.setUrl("http://ks.pconline.com.cn/product.jsp?q="+result);
					
				}
				
			});

			
		}
		else
		{
		f.setUrl("http://www.google.cn/search?hl=zh-CN&q="+searchstr);
		}
		
		return f;
		
	}

}
